﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using rbac.api.Filters;
using rbac.contracts.Dto.Input;
using rbac.contracts.Dto.Output;
using rbac.contracts.Interface;

namespace rbac.api.Controllers
{
    /// <summary>
    /// 角色权限
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class RolePermissionController : ControllerBase
    {

        IRolePermissionService _rolePermissionService;

        public RolePermissionController(IRolePermissionService rolePermissionService)
        {
            _rolePermissionService = rolePermissionService;
        }

        /// <summary>
        /// 分配权限
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [RbacAuthorize("Admin")]
        public Results<int> DistributeRolePermission([FromBody]DistributeRolePermissionsInput input)
        {
            return Results<int>.DataResult(_rolePermissionService.DistributeRolePermission(input));
        }

        /// <summary>
        /// 权限查询
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        [HttpGet("{roleId}")]
        //[RbacAuthorize("AdminAndCustomer")]
        public Results<List<PermissionDto>> GetPermissionByRoleId(int roleId)
        {
            return Results<List<PermissionDto>>.DataResult(_rolePermissionService.GetPermissionByRoleId(roleId));
        }


    }
}
